package com.ruoyi.course.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.course.utils.RoleUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.course.mapper.CdCourseTeacherMapper;
import com.ruoyi.course.domain.CdCourseTeacher;
import com.ruoyi.course.service.ICdCourseTeacherService;

/**
 * 课程-教师关联Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-12-18
 */
@Service
public class CdCourseTeacherServiceImpl implements ICdCourseTeacherService 
{
    @Autowired
    private CdCourseTeacherMapper cdCourseTeacherMapper;

    @Autowired
    private RoleUtils roleUtils;

    /**
     * 查询课程-教师关联
     * 
     * @param teacherId 课程-教师关联主键
     * @return 课程-教师关联
     */
    @Override
    public CdCourseTeacher selectCdCourseTeacherByTeacherIdAndCourseId(Long teacherId, Long courseId)
    {
        return cdCourseTeacherMapper.selectCdCourseTeacherByTeacherIdAndCourseId(teacherId, courseId);
    }

    /**
     * 查询课程-教师关联列表
     * 
     * @param cdCourseTeacher 课程-教师关联
     * @return 课程-教师关联
     */
    @Override
    public List<CdCourseTeacher> selectCdCourseTeacherList(CdCourseTeacher cdCourseTeacher)
    {
        return cdCourseTeacherMapper.selectCdCourseTeacherList(cdCourseTeacher);
    }

    /**
     * 新增课程-教师关联
     * 
     * @param cdCourseTeacher 课程-教师关联
     * @return 结果
     */
    @Override
    public int insertCdCourseTeacher(CdCourseTeacher cdCourseTeacher)
    {
        cdCourseTeacher.setCreateBy(SecurityUtils.getUsername());
        cdCourseTeacher.setCreateTime(DateUtils.getNowDate());
        return cdCourseTeacherMapper.insertCdCourseTeacher(cdCourseTeacher);
    }

    /**
     * 修改课程-教师关联
     * 
     * @param cdCourseTeacher 课程-教师关联
     * @return 结果
     */
    @Override
    public int updateCdCourseTeacher(CdCourseTeacher cdCourseTeacher)
    {
        cdCourseTeacher.setUpdateBy(SecurityUtils.getUsername());
        cdCourseTeacher.setUpdateTime(DateUtils.getNowDate());
        return cdCourseTeacherMapper.updateCdCourseTeacher(cdCourseTeacher);
    }

    /**
     * 批量删除课程-教师关联
     * 
     * @param teacherIds 需要删除的课程-教师关联主键
     * @return 结果
     */
    @Override
    public int deleteCdCourseTeacherByTeacherIds(Long[] teacherIds)
    {
        return cdCourseTeacherMapper.deleteCdCourseTeacherByTeacherIds(teacherIds);
    }

    /**
     * 删除课程-教师关联信息
     * 
     * @param teacherId 课程-教师关联主键
     * @return 结果
     */
    @Override
    public int deleteCdCourseTeacherByTeacherId(Long teacherId)
    {
        return cdCourseTeacherMapper.deleteCdCourseTeacherByTeacherId(teacherId);
    }

    /**
     * 查询教师指导的课程
     * @return
     */
    @Override
    public List<CdCourseTeacher> listBySelf() {
        CdCourseTeacher cdCourseTeacher = new CdCourseTeacher();
        if (roleUtils.isTeacher() && !roleUtils.isDirector()) {
            // 如果是系主任，则查看所有，如果是教师且非系主任，只查看自己指导的
            cdCourseTeacher.setTeacherId(SecurityUtils.getUserId());
        }
        return cdCourseTeacherMapper.selectCdCourseTeacherList(cdCourseTeacher);
    }
}
